package com.mycjj.android.util;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.mycjj.android.R;


import android.content.Context;
import android.util.Log;

public class AppConfigs {

	private static boolean   init = false;
    private static boolean  debug = false;
    private static String dbPath = "/data/data/com.mycjj.android/databases/city_db.db";
    private static String dbDir = "/data/data/com.mycjj.android/databases/";

    public static void initConfig(Context context){
        // if true , it means , have load the infos, so need not to load again .
        if(init)
            return;
        try {
            //read the configure file to the memory
            InputStream inputStream =  context.getResources().openRawResource(R.raw.config);
            Properties properties  = new Properties();
            properties.load(inputStream);
            debug = Boolean.valueOf(properties.getProperty("debug"));
            dbDir = properties.getProperty("dbDir");
            File file = new File(dbDir);
            if(!file.exists()){
            	file.mkdirs();
            }
            dbPath = properties.getProperty("dbPath");
            Log.e("mark","dbDir:"+dbDir+"dbDir exists:"+(new File(dbDir)).exists()+";dbPath:"+dbPath);
            init = true;
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static boolean isDebug() {
        return debug;
    }
    
    public static String getDBPath(){
    	return dbPath;
    }
    
}
